﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Ninject.Modules;
using mBlog.Data;
using Ninject;
using mBlog.Services;

namespace mBlog.Infrastructure
{
    public class mBlogDependencyResolver : IDependencyResolver
    {
        private static StandardKernel kernel = new StandardKernel(new mBlogModule());

        public object GetService(Type serviceType)
        {
            return kernel.TryGet(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return kernel.GetAll(serviceType);
        }
    }

    public class mBlogModule : NinjectModule
    {
        public override void Load()
        {
            Bind<IPostService>().To<PostService>();
            Bind<ICategoryService>().To<CategoryService>();
            Bind<ITagService>().To<TagService>();


            Bind<mBlogContext>().ToSelf().InSingletonScope();
        }
    }
}
